﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _default : System.Web.UI.MasterPage
{
    DBConnection connect = new DBConnection();
    static DataTable tblGioHang = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {


            if (Session["account"] != null)
            {
                txtSuccess.Visible = true;
                linkDangXuat.Visible = true;
                txtGioHang.Visible = true;
                txtSoLuong.Visible = true;

                if (Session["GioHang"] != null)
                {
                    tblGioHang = Session["GioHang"] as DataTable;

                }
                int soSP = tblGioHang.Rows.Count;
                txtSoLuong.Text = soSP + " SP ";
                txtGioHang.Text = "Xem giỏ hàng: ";
                linkDangNhap.Visible = false;
                linkDangKy.Visible = false;
                if (Session["Admin"] != null)
                {
                    linkAdmin.Visible = true;
                }
                txtSuccess.Text = "Xin chào: " + Session["account"] + " &nbsp /";
            }

            LoadData();
        }
    }

    private void LoadData()
    {

        CateRepeater.DataSource = connect.GetAllCategory();
        CateRepeater.DataBind();
    }
    protected void btnSeach_click(object sender, EventArgs e)
    {
        if (txtSeach.Text == "" && seach_price.SelectedItem.Value == "0")
        { Response.Write("<script>alert('Bạn phải nhập tên hoặc chọn giá trước khi tìm!...')</script>"); }
        else
        {
            String ProName = txtSeach.Text;
            String Price = seach_price.SelectedItem.Value;
            Response.Redirect("TimKiemSP.aspx?ProName=" + ProName + "&Price=" + Price);
        }

        Session["SeachPrice"] = seach_price.SelectedItem.Value;

    }
}
